From: Giovanni Campagna Date: Sat, 19 Feb 2011 15:19:31 +0000 (+0100) Subject: ShellWindowTracker: fix a reference counting bug X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~8910 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=5683bb9b8efbc5bc05c50984fcc817b5ddbec3a6;p=gnome-shell.git ShellWindowTracker: fix a reference counting bug When retrieving a ShellApp from the GHashTable of child processes, we need to take an extra reference, that the GHashTable of windows to apps will own. Also add some documentation to avoid repeating this bug in the future. https://bugzilla.gnome.org/show_bug.cgi?id=642699 --- diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c index a0255b501..25ee54437 100644 --- a/src/shell-window-tracker.c +++ b/src/shell-window-tracker.c @@ -382,10 +382,21 @@ get_app_from_window_group (ShellWindowTracker *monitor, return result; } +/** + * get_app_from_window_pid: + * @monitor: a #ShellWindowTracker + * @window: a #MetaWindow + * + * Check if the pid associated with @window corresponds to an + * application we launched. + * + * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL + */ static ShellApp * get_app_from_window_pid (ShellWindowTracker *tracker, MetaWindow *window) { + ShellApp *result; int pid; if (meta_window_is_remote (window)) @@ -396,7 +407,11 @@ get_app_from_window_pid (ShellWindowTracker *tracker, if (pid == -1) return NULL; - return g_hash_table_lookup (tracker->launched_pid_to_app, GINT_TO_POINTER (pid)); + result = g_hash_table_lookup (tracker->launched_pid_to_app, GINT_TO_POINTER (pid)); + if (result != NULL) + g_object_ref (result); + + return result; } /** @@ -405,6 +420,8 @@ get_app_from_window_pid (ShellWindowTracker *tracker, * Determines the application associated with a window, using * all available information such as the window's MetaGroup, * and what we know about other windows. + * + * Returns: (transfer full): a #ShellApp, or NULL if none is found */ static ShellApp * get_app_for_window (ShellWindowTracker *monitor,